import {getSimpleDictDataList} from '@/api/system/dict.js'
const AccessTokenKey = 'ACCESS_TOKEN'
const RefreshTokenKey = 'REFRESH_TOKEN'

// ========== Token 相关 ==========

export function getAccessToken() {
  return uni.getStorageSync(AccessTokenKey)
}

export function getRefreshToken() {
  return uni.getStorageSync(RefreshTokenKey)
}

export function setToken(token) {
  uni.setStorageSync(AccessTokenKey, token.accessToken)
  uni.setStorageSync(RefreshTokenKey, token.refreshToken)
}

export function removeToken() {
  uni.removeStorageSync(AccessTokenKey)
  uni.removeStorageSync(RefreshTokenKey)
}

export function setTenantId(tenantId) {
  uni.setStorageSync('tenantId', tenantId)
}

export function getTenantId() {
  return uni.getStorageSync('tenantId')
}

export function setDictOptions(dictOptions) {
  uni.setStorageSync('dictOptions', dictOptions)
}

export function getDictOptions() {
  return uni.getStorageSync('dictOptions')
}


// *************公共字典**********************
export async function getIntDictOptions(type){
	// let info = await getSimpleDictDataList(type);
	// 判断缓存中是否有
	let dictOptions = getDictOptions();
	if(dictOptions.length <= 0){
		let info = await getSimpleDictDataList(type);
		dictOptions = info.data
	}
	let arr = [];
	dictOptions.forEach(item=>{
		if(item.dictType == type){
			arr.push({
			  value: Number(item.value),
			  text: item.label,
			  colorType: item.colorType,
			  cssClass: item.cssClass
			})
		}
	})
	console.log(arr);
	return arr
}